/**
 * Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

/*!
 * \file matmul_var.h
 * \brief matmul variable manager
 */

#ifndef IMPL_MATMUL_MODULES_MATMUL_VAR_H
#define IMPL_MATMUL_MODULES_MATMUL_VAR_H

#include "../matmul_module.h"

namespace matmul {
template <typename IMPL, const auto &MM_CFG, class INPUT_TYPE, typename = void>
class MatmulVar {
    using SrcT = typename INPUT_TYPE::T;
    using TransT = typename INPUT_TYPE::TRANS_T;
public:

#if __CCE_AICORE__ < 220
    __aicore__ inline LocalTensor<uint8_t> GetLocalWorkspace(int offset) const
    {
        return MATMUL_CONST_PARAM_VAR.localWorkspace[offset];
    }

    __aicore__ inline int32_t GetTransLength() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetTransLength();
    }

    __aicore__ inline int GetNd2NzOffset() const
    {
        return MATMUL_CONST_PARAM_VAR.nd2nz0ffset;
    }

    __aicore__ inline int32_t GetDepthL1CacheUB()
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetDepthAL1CacheUB();
    }
#endif
};

template <typename IMPL, class INPUT_TYPE, const auto &MM_CFG>
class MatmulVar<IMPL, MM_CFG, INPUT_TYPE, enable_if_t<INPUT_TYPE::TAG == InputTypeTag::B>> {
    using SrcT = typename INPUT_TYPE::T;
    using TransT = typename INPUT_TYPE::TRANS_T;
public:

#if __CCE_AICORE__ < 220
    __aicore__ inline LocalTensor<uint8_t> GetLocalWorkspace(int offset) const
    {
        return MATMUL_CONST_PARAM_VAR.localWorkspace[offset];
    }

    __aicore__ inline int32_t GetTransLength() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetTransLength();
    }

    __aicore__ inline int GetNd2NzOffset() const
    {
        return MATMUL_CONST_PARAM_VAR.nd2nz0ffset;
    }

    __aicore__ inline int32_t GetDepthL1CacheUB() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetDepthBL1CacheUB();
    }
#endif
};

template <typename IMPL, class INPUT_TYPE, const auto &MM_CFG>
class MatmulVar<IMPL, MM_CFG, INPUT_TYPE, enable_if_t<INPUT_TYPE::TAG == InputTypeTag::C>> {
    using SrcT = typename INPUT_TYPE::T;
    using TransT = typename INPUT_TYPE::TRANS_T;
public:

    __aicore__ inline int32_t GetTransLength()
    {
        return MATMUL_PARAM_VAR.tiling_.GetTransLength();
    }

    __aicore__ inline int32_t &GetCo2Offset()
    {
        return MATMUL_PARAM_VAR.co2Offset;
    }

    __aicore__ inline int32_t GetTransOffset()
    {
        return MATMUL_PARAM_VAR.transOffset;
    }

    __aicore__ inline __ubuf__ uint8_t* GetCacheUBWorkspaceAddr()
    {
        return MATMUL_PARAM_VAR.cacheUBWorkspaceAddr;
    }

    __aicore__ inline int32_t GetND2NZOffset()
    {
        return MATMUL_PARAM_VAR.nd2nz0ffset;
    }

    __aicore__ inline LocalTensor<uint8_t> GetLocalWorkspace()
    {
        return MATMUL_PARAM_VAR.localWorkspace;
    }
};
}      // namespace matmul
#endif // IMPL_MATMUL_MODULES_MATMUL_VAR_H
